package com.hz.ruoyilgorder.config;

import com.hz.rouyigonggong.domain.LgOutOrder;
import com.hz.rouyigonggong.domain.dto.LgOutOrderDTO;
import org.springframework.beans.BeanUtils;

/**
 * @version 1.0
 * @Author yzw
 * @Date 2025/3/9 16:34
 * @注释
 */
public class LgOutOrderConverter {


    /**
     * 将 LgOutOrder 转换为 LgOutOrderDTO
     */
    public static LgOutOrderDTO toDTO(LgOutOrder entity, String sellerName, String sellerContact, String inspectorName, String goodsName) {
        if (entity == null) {
            return null;
        }

        LgOutOrderDTO dto = new LgOutOrderDTO();
        // 复制基础字段
        BeanUtils.copyProperties(entity, dto);

//        // 处理 DTO 特有字段
//        dto.setGoodsUnit(new String(entity.getUnit())); // unit → goodsUnit
        dto.setSellerName(sellerName);
        dto.setSellerContact(sellerContact);
        dto.setInspectorName(inspectorName);
        dto.setGoodsName(goodsName);

        return dto;
    }

    /**
     * 将 LgOutOrderDTO 转换为 LgOutOrder
     */
    public static LgOutOrder toEntity(LgOutOrderDTO dto) {
        if (dto == null) {
            return null;
        }

        LgOutOrder entity = new LgOutOrder();
        // 复制基础字段
        BeanUtils.copyProperties(dto, entity);

        // 处理 Entity 特有字段
        if (dto.getGoodsUnit() != null){
            entity.setUnit(Integer.parseInt(dto.getGoodsUnit())); // goodsUnit → unit
        }
        if(dto.getGoodsName() != null){
            entity.setGoodsId(Integer.parseInt(dto.getSubGoodsName()));
        }


        return entity;
    }
}
